package com.dev.toolkit.api;

import com.dev.toolkit.common.response.Result;
import com.dev.toolkit.domain.entity.DatabaseConfigEntity2;
import com.dev.toolkit.service.IDatabaseConfigService2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @date 2024/06/05 16:56
 * @description 数据库连接配置信息
 */
@RestController
@RequestMapping("/api/v2/database/config")
public class DatabaseConfigController2 {
    @Resource
    private IDatabaseConfigService2 databaseConfigService2;

    @PostMapping("/save")
    public Result<Void> saveOrUpdateDbConfig(@RequestBody DatabaseConfigEntity2 entity2) {
        databaseConfigService2.saveOrUpdateDbConfig(entity2);
        return Result.success();
    }

    @GetMapping("/list")
    public Result<List<DatabaseConfigEntity2>> getDbConfigList(@RequestParam(value = "searchParam", required = false) String searchParam) {
        return Result.success(databaseConfigService2.getDbConfigList(searchParam));
    }

    @DeleteMapping("/remove/{id}")
    public Result<Void> saveOrUpdateDbConfig(@PathVariable("id") Long id) {
        databaseConfigService2.removeById(id);
        return Result.success();
    }
}